fix: add Gradle 9 compatibility - #168
Conversation
Gradle 9 removed several deprecated APIs that this plugin relied on.
This commit updates the plugin to use the new APIs and modernizes the
build configuration to support the changes.
1. Core API Changes (Gradle 9 removals)
- Replace `fileMode = 493` with `filePermissions { unix("rwxr-xr-x") }`
The CopySpec.fileMode property was deprecated in Gradle 8 and removed
in Gradle 9. The new filePermissions API provides the same functionality.
- Replace `project.exec {}` with injected `ExecOperations.exec {}`
The Project.exec() method was deprecated in Gradle 7.5 and removed in
Gradle 9. Tasks must now use service injection to obtain ExecOperations.
This requires changing task classes from `open class` to `abstract class`.
2. Build Configuration Updates
These changes are required because the new Gradle 9 APIs (filePermissions,
ExecOperations) are only available in Gradle 8.3+, so we must compile
against a newer Gradle version:
- Gradle wrapper: 7.1.1 → 8.5
Required to compile against the new APIs (filePermissions added in 8.3)
- Kotlin: 1.3.50 → 1.9.22
The old Kotlin Gradle plugin uses APIs removed in Gradle 8.x
- AGP: 4.0.1 → 8.2.0
Required for Gradle 8.5+ compatibility
- Java target: 1.8 → 17
Required by both Gradle 8.5+ and AGP 8.x
- plugin-publish: 0.14.0 → 1.2.1
The old version uses the `pluginBundle {}` DSL which was removed.
Metadata (website, vcsUrl, tags) now goes in `gradlePlugin {}` block.
- Add Guava dependency
Versions.groovy uses Guava collections which were previously provided
transitively by AGP 4.x but are no longer included in AGP 8.x.
- Add `null` branch to `when` expression in CargoBuildTask
Kotlin 1.7+ requires exhaustive `when` for sealed classes with
nullable types.
3. Test Matrix Updates
- Updated supportedVersions to test AGP 8.x with Gradle 8.x
- Updated jdkVersionFor() to use Java 17 for AGP 8.x
Fixes mozilla#160
| // there's a way to specify them in the cargo command line -- rustc accepts | ||
| // them if passed in directly with `--cfg`, and cargo will pass them to rustc | ||
| // if you use them as default featureSpec. | ||
| // Kotlin 1.9+ requires exhaustive when for sealed classes with nullable types |
There was a problem hiding this comment.
happy to remove all the comments in the review process, but figured it would be easier to understand how this small file permissions change (the actual removed API) triggered cascading change in other dependencies.
| "7.0.0": ["7.1.1"], | ||
| "4.2.2": ["6.8.3", "7.1.1"], | ||
| "4.1.3": ["6.5.1", "6.8.3"], | ||
| "4.0.2": ["6.1.1", "6.8.3"], | ||
| "3.6.4": ["5.6.4", "6.8.3"], | ||
| "3.5.4": ["5.4.1", "5.6.4", "6.8.3"], | ||
| "3.1.2": ["4.10.2"] | ||
| "8.2.0": ["8.5"], | ||
| "8.3.0": ["8.5"], | ||
| "8.4.0": ["8.6"], | ||
| "8.5.0": ["8.7"], | ||
| "8.6.0": ["8.7"], |
There was a problem hiding this comment.
not sure what to keep here to avoid breaking code - I tested it with 8.5.0 locally.
perhaps it would require a minor version bump to avoid breaking old code?
|
I'd love to see gradle 9 compatibility, but I'm wondering whether this project is still alive and whether this PR would be reviewed by maintainers |
|
Thanks for this, and sorry for the complete radio silence. Maintaining this plugin is something I do off the side of my desk and it rarely gets to the top of my pile. I incorporated your excellent work into #175. Thanks again! |
Gradle 9 removed several deprecated APIs that this plugin relied on. This commit updates the plugin to use the new APIs and modernizes the build configuration to support the changes.
Replace
fileMode = 493withfilePermissions { unix("rwxr-xr-x") }The CopySpec.fileMode property was deprecated in Gradle 8 and removed in Gradle 9. The new filePermissions API provides the same functionality.Replace
project.exec {}with injectedExecOperations.exec {}The Project.exec() method was deprecated in Gradle 7.5 and removed in Gradle 9. Tasks must now use service injection to obtain ExecOperations. This requires changing task classes fromopen classtoabstract class.These changes are required because the new Gradle 9 APIs (filePermissions, ExecOperations) are only available in Gradle 8.3+, so we must compile against a newer Gradle version:
Gradle wrapper: 7.1.1 → 8.5 Required to compile against the new APIs (filePermissions added in 8.3)
Kotlin: 1.3.50 → 1.9.22 The old Kotlin Gradle plugin uses APIs removed in Gradle 8.x
AGP: 4.0.1 → 8.2.0 Required for Gradle 8.5+ compatibility
Java target: 1.8 → 17 Required by both Gradle 8.5+ and AGP 8.x
plugin-publish: 0.14.0 → 1.2.1 The old version uses the
pluginBundle {}DSL which was removed. Metadata (website, vcsUrl, tags) now goes ingradlePlugin {}block.Add Guava dependency Versions.groovy uses Guava collections which were previously provided transitively by AGP 4.x but are no longer included in AGP 8.x.
Add
nullbranch towhenexpression in CargoBuildTask Kotlin 1.7+ requires exhaustivewhenfor sealed classes with nullable types.Fixes #160